{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c17cc194",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "zhichao\n",
      "123456\n",
      "23\n",
      "['youge', 123456, 28]\n"
     ]
    }
   ],
   "source": [
    "# week05: 数据结构之列表\n",
    "users_list = [\"zhichao\",\"youge\",\"xiaoming\"]\n",
    "password_list = [123456,789654,273843]\n",
    "age_list = [23,28,18]\n",
    "# ...\n",
    "# 列表的嵌套\n",
    "info_list = [[\"zhichao\",123456,23],[\"youge\",123456,28]]\n",
    "\n",
    "print(users_list[0])\n",
    "print(password_list[0])\n",
    "print(age_list[0])\n",
    "print(info_list[-1])# -1表示反向取值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "358aa260",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Mary', 'Jan']\n",
      "['Mary', 'Jan', 'Jack']\n",
      "['Mike', 'Mary']\n",
      "['Mike', 'Mary']\n",
      "['Mary', 'Jan']\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Mary\",\"Jan\",\"Jack\"]\n",
    "# 知识点 slices(切片) 数值是指 values在list中的位置\n",
    "\n",
    "# 1. 正向取值\n",
    "# list 取值 “:”右边的值取不到 例如[1:3] 3 这个位置取不到\n",
    "print(names[1:3])\n",
    "print(names[1:4])\n",
    "print(names[0:2])\n",
    "# 如果 左侧的值是0 即从0开始取值，0可以省略不写\n",
    "print(names[:2])\n",
    "\n",
    "# 2. 反向取值\n",
    "# list 取值 “:”右边的值取不到 例如[-3:-1] -1 这个位置取不到\n",
    "# 注意： 取到最后一个值，不能写 0 省略不写即可\n",
    "print(names[-3:-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a7f8ecb8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[1, 3, 5]\n",
      "[1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "num = [1,2,3,4,5,6,7,8,9]\n",
    "# 对比 range\n",
    "print(list(range(10)))\n",
    "print(num[:6:2])\n",
    "print(num[0:6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f8f3a2a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-10-27\n",
      "['2021', '10', '27']\n",
      "2021\n"
     ]
    }
   ],
   "source": [
    "#split() 通过指定\"分隔符\"!!对\"字符\"!!串进行切片，如果参数 num 有指定值，则分隔 num+1 个子字符串\n",
    "user_input_time = \"2021-10-27\"\n",
    "# 字符串拆分，方法 split 拆分完的结果是一个 列表\n",
    "print(user_input_time)\n",
    "print(user_input_time.split('-'))\n",
    "print(user_input_time.split('-')[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f259194",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
